#ifndef GENERIC_FRESNEL_ASYMP_H
#define GENERIC_FRESNEL_ASYMP_H
#include "kernel_tensor.h"
#include "genericFresnelCos.h"
namespace AscendC {
    constexpr float FN[] = {
        4.21543555043677546506E-1,  1.43407919780758885261E-1,
        1.15220955073585758835E-2,  3.45017939782574027900E-4,
        4.63613749287867322088E-6,  3.05568983790257605827E-8,
        1.02304514164907233465E-10, 1.72010743268161828879E-13,
        1.34283276233062758925E-16, 3.76329711269987889006E-20,
    };
    constexpr float FD[] = {
        1.0,
        7.51586398353378947175E-1,
        1.16888925859191382142E-1,
        6.44051526508858611005E-3,
        1.55934409164153020873E-4,
        1.84627567348930545870E-6,
        1.12699224763999035261E-8,
        3.60140029589371370404E-11,
        5.88754533621578410010E-14,
        4.52001434074129701496E-17,
        1.25443237090011264384E-20,
    };
    constexpr float GN[] = {
        5.04442073643383265887E-1,  1.97102833525523411709E-1,
        1.87648584092575249293E-2,  6.84079380915393090172E-4,
        1.15138826111884280931E-5,  9.82852443688422223854E-8,
        4.45344415861750144738E-10, 1.08268041139020870318E-12,
        1.37555460633261799868E-15, 8.36354435630677421531E-19,
        1.86958710162783235106E-22,
    };
    constexpr float GD[] = {
        1.0,
        1.47495759925128324529E0,
        3.37748989120019970451E-1,
        2.53603741420338795122E-2,
        8.14679107184306179049E-4,
        1.27545075667729118702E-5,
        1.04314589657571990585E-7,
        4.60680728146520428211E-10,
        1.10273215066240270757E-12,
        1.38796531259578871258E-15,
        8.39158816283118707363E-19,
        1.86958710162783236342E-22,
    };
  constexpr float HALF_PI = 1.5707963267948966;
  constexpr float PI = 3.1415926535897932384626433832795;
__aicore__ inline void GenericFresnelAsymp(const LocalTensor<float>& dst, const LocalTensor<float>& src,
    const LocalTensor<float>& tmp1, const LocalTensor<float>& tmp2, const LocalTensor<float>& tmp3, 
    const LocalTensor<float>& tmp4, const LocalTensor<float>& tmp5, const LocalTensor<float>& tmp6, 
    const uint32_t length)
{
    Mul(tmp1, src, src, length); 
    Duplicate(dst, (float)1, length);
    Muls(tmp2, tmp1, PI, length);
    Div(tmp2, dst, tmp2, length); 
    Mul(tmp3, tmp2, tmp2, length); 
    Muls(tmp4, tmp3, FN[0], length);
    Adds(tmp4, tmp4, FN[1], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[2], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[3], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[4], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[5], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[6], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[7], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[8], length);
    Mul(tmp4, tmp4, tmp3, length);
    Adds(tmp4, tmp4, FN[9], length); 
    Muls(tmp5, tmp3, FD[0], length);
    Adds(tmp5, tmp5, FD[1], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[2], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[3], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[4], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[5], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[6], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[7], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[8], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[9], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, FD[10], length); 
    Div(tmp4, tmp4, tmp5, length);
    Mul(tmp4, tmp4, tmp3, length);
    Muls(tmp4, tmp4, (float)(-1), length);
    Adds(tmp4, tmp4, (float)1, length); 
    Muls(tmp5, tmp3, GN[0], length);
    Adds(tmp5, tmp5, GN[1], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[2], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[3], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[4], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[5], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[6], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[7], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[8], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[9], length);
    Mul(tmp5, tmp5, tmp3, length);
    Adds(tmp5, tmp5, GN[10], length); 
    Muls(dst, tmp3, GD[0], length);
    Adds(dst, dst, GD[1], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[2], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[3], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[4], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[5], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[6], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[7], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[8], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[9], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[10], length);
    Mul(dst, dst, tmp3, length);
    Adds(dst, dst, GD[11], length); 
    Div(tmp5, tmp5, dst, length);
    Mul(tmp5, tmp5, tmp2, length); 
    Muls(tmp1, tmp1, HALF_PI, length); 
    Adds(tmp2, tmp1, HALF_PI, length); 
    SinCompute(tmp3, tmp2, dst, tmp6, length); 
    SinCompute(tmp2, tmp1, dst, tmp6, length); 
    Muls(src, src, PI, length); 
    Mul(dst, tmp4, tmp2, length); 
    Mul(tmp5, tmp5, tmp3, length); 
    Sub(dst, dst, tmp5, length); 
    Div(dst, dst, src, length);
    Adds(dst, dst, (float)0.5, length);
}
}
#endif